home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Help with sin() - big problem
- Date: 7 Mar 1996 18:14:42 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4hnql2$3ks@umbc9.umbc.edu>
- References: <4hhusi$49i@sunburst.ccs.yorku.ca>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Naftali Sturm <yu114405@yorku.ca> wrote:
- |> I have a big problem.
- |> I am making a math and trigonometry program which, one of its functions
- |> is to compute the sine of a number.
- |> The way I did it was.
- |> result = sin(numb);
- |>
- |> result and num are both float's.
- |> The problem is that when numb is 1.0, the
- |> program gives me .84147 , and when numb is 45.0
- |> the program gives me .85090, and each number is a different result.
- |> However I took a look at my sine table in my trigonometry book, and
- |> it says the sine of 1 is .018, the sine of 45 is .707, and
- |> different results than what my program said.
- |> Why?
- |>
- |> thank(you); for(your=help;;) { }
-
- Well the <math.h> library sin() function uses radians instead of degrees.
- A radian is the length of the radius of a particular circle and in
- Euclidean geometry all circles have exactly 2*pi of these. So a 45 degree
- angle would be pi/4 radians. Using the simple fact that there is 360
- degrees in a circle you can multiply all your degree measures by
- pi/180 before passing them to sin() and everything will work fine.
- Just make sure everything is floating point in your actual code ;-).
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-